package com.yzl.nacos.user.common.exception;

import javax.servlet.http.HttpServletResponse;

import com.google.common.base.Throwables;
import com.yzl.nacos.user.common.entity.ErrorCode;
import com.yzl.nacos.user.common.enums.ErrorCodeEnum;

import lombok.extern.slf4j.Slf4j;

/**
 * <p>
 * MSG 消息异常类
 * </p>
 *
 * @author Caratacus
 */
@Slf4j
public class Crown2Exception extends ApiException {

	private static final long serialVersionUID = 1L;

	public Crown2Exception(int httpCode, String msg, Exception ex) {
		this(httpCode, msg);
		if (httpCode < HttpServletResponse.SC_INTERNAL_SERVER_ERROR) {
			log.info("Info: MsgException Info {}", ex.getMessage());
		} else {
			log.warn("Warn: MsgException Warn {}", Throwables.getStackTraceAsString(ex));
		}

	}

	public Crown2Exception(int httpCode, String msg) {
		super(ErrorCode.builder().error(ErrorCodeEnum.MSG_EXCEPTION.name()).status(httpCode).msg(msg).build());
	}

}